﻿Imports DevExpress.XtraLayout
Imports IControl.IControls
Imports DevExpress.XtraEditors
Imports DevExpress.XtraGrid.Views.Grid
Imports System.Drawing

Public Class IFormBaoCao
    Private WithEvents view As DevExpress.XtraGrid.Views.Grid.GridView
    Private Sub view_CustomDrawRowIndicator(sender As Object, e As DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs) Handles view.CustomDrawRowIndicator
        Dim view As GridView = DirectCast(sender, GridView)
        Dim indicatorIcon As Boolean = False
        If e.RowHandle >= 0 Then 'trừ trường hợp -1
            'Check whether the indicator cell belongs to a data row
            If e.Info.IsRowIndicator Then
                e.Info.DisplayText = (e.RowHandle + 1).ToString()
                If Not indicatorIcon Then
                    e.Info.ImageIndex = -1
                End If
            End If
        End If
    End Sub
    Public Sub setAppearanceSearchLookupEdit(ByVal lc As LayoutControl)
        For Each item In lc.Items
            If TypeOf item Is LayoutControlItem Then
                Dim ct As Control = DirectCast(item, LayoutControlItem).Control
                If TypeOf ct Is BaseEdit Then
                    If TypeOf ct Is ISearchLookupEdit Then
                        DirectCast(ct, ISearchLookupEdit).Properties.View.IndicatorWidth = 55
                        DirectCast(ct, ISearchLookupEdit).Properties.View.OptionsView.EnableAppearanceEvenRow = True
                        DirectCast(ct, ISearchLookupEdit).Properties.View.Appearance.EvenRow.BackColor = Color.LightCyan
                        DirectCast(ct, ISearchLookupEdit).Properties.NullText = "[Chọn]"
                        Me.view = CType(ct, SearchLookUpEdit).Properties.View
                        AddHandler view.CustomDrawRowIndicator, AddressOf view_CustomDrawRowIndicator
                    End If
                End If
            End If
        Next
    End Sub
    Private Sub LoadThoiGian()
        Dim dt As New DataTable
        ' Create four typed columns in the DataTable.
        dt.Columns.Add("ma", GetType(String))
        dt.Columns.Add("ten", GetType(String))
        dt.Rows.Add("TN", "Tháng này")
        dt.Rows.Add("TT", "Tháng trước")
        dt.Rows.Add("T1", "Tháng 1")
        dt.Rows.Add("T2", "Tháng 2")
        dt.Rows.Add("T3", "Tháng 3")
        dt.Rows.Add("T4", "Tháng 4")
        dt.Rows.Add("T5", "Tháng 5")
        dt.Rows.Add("T6", "Tháng 6")
        dt.Rows.Add("T7", "Tháng 7")
        dt.Rows.Add("T8", "Tháng 8")
        dt.Rows.Add("T9", "Tháng 9")
        dt.Rows.Add("T10", "Tháng 10")
        dt.Rows.Add("T11", "Tháng 11")
        dt.Rows.Add("T11", "Tháng 12")
        dt.Rows.Add("All", "Tất cả")
        Me.ThoiGianISearchLookupEdit.Properties.DataSource = dt
    End Sub
    Private Sub IFormBaoCao_Load(sender As Object, e As EventArgs) Handles Me.Load
        setAppearanceSearchLookupEdit(Me.LayoutControl1)
        LoadThoiGian()
        Me.ThoiGianISearchLookupEdit.EditValue = "TN"
        Me.TuNgayIDateEdit.EditValue = getNgayDauThang(Today)
        Me.DenNgayIDateEdit.EditValue = getNgayCuoiThang(Today)
    End Sub

    Private Sub ThoiGianISearchLookupEdit_EditValueChanged(sender As Object, e As EventArgs) Handles ThoiGianISearchLookupEdit.EditValueChanged
        setDMThoiGian(Me.ThoiGianISearchLookupEdit, TuNgayIDateEdit, DenNgayIDateEdit)
    End Sub

    Private Sub BarButtonItemThoat_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemThoat.ItemClick
        Me.Close()
    End Sub
    ''' <summary>
    ''' lấy giá trị từ ngày (kiểu date)
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getTuNgay() As Date
        Return CDate(TuNgayIDateEdit.EditValue)
    End Function
    ''' <summary>
    ''' lấy giá trị đến ngày (kiểu date)
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getDenNgay() As Date
        Return CDate(DenNgayIDateEdit.EditValue)
    End Function
End Class